﻿using System.Reflection;
using Windows.UI.Xaml;

namespace XamlInspector.Model.Properties
{
    public class XamlThicknessProperty : XamlProperty
    {
        private Thickness _thickness;

        public XamlThicknessProperty(PropertyInfo propertyInfo, object element, string category = "Common")
            : base(propertyInfo, element, category)
        {
            _thickness = (Thickness)propertyInfo.GetValue(element);
        }

        public double Top
        {
            get { return _thickness.Top; }
            set
            {
                _thickness.Top = value;
                UpdateTarget();
            }
        }

        public double Bottom
        {
            get { return _thickness.Bottom; }
            set
            {
                _thickness.Bottom = value;
                UpdateTarget();
            }
        }

        public double Left
        {
            get { return _thickness.Left; }
            set
            {
                _thickness.Left = value;
                UpdateTarget();
            }
        }

        public double Right
        {
            get { return _thickness.Right; }
            set
            {
                _thickness.Right = value;
                UpdateTarget();
            }
        }

        private void UpdateTarget()
        {
            PropertyInfo.SetValue(Element, _thickness);
        }
    }
}
